<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>APP</title>
		<link href="css/weui.min.css" rel="stylesheet" />
		<link href="css/jquery-weui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link href="css/flex.css" rel="stylesheet" />
		<link href="fonts/iconfont.css" rel="stylesheet" />
	</head>
	<style>
		.main-body {
			background-color: #eee;
			top: 180px
		}
		
		.order-menu {
			text-align: center;
		}
		
		.order-menu .weui-flex__item {
			padding-top: 10px;
			height: 80px;
			font-size: 14px;
			color: #666;
		}
		
		.order-menu .weui-flex__item i {
			font-size: 25px;
			display: block;
			color: #999;
		}
		
		.order-menu .weui-flex__item img {
			display: block;
			margin: auto;
		}
		
		.user-info {
			position: relative;
			height: 180px;
			background-color: #45a75c;
		}
		
		.user-icon {
			position: absolute;
			left: 20px;
			top: 35px;
			width: 60px;
			height: 60px;
			border-radius: 50%;
			border: #eee 1px solid;
		}
		
		.user-name {
			position: absolute;
			left: 90px;
			top: 43px;
			color: #fff;
			font-size: 16px;
		}
		
		.user-level {
			position: absolute;
			left: 90px;
			top: 70px;
			color: #fff;
			font-size: 12px;
		}
		
		.user-edit {
			position: absolute;
			right: 55px;
			top: 35px;
			font-size: 16px; 
			color: #fff
		}
		
		.user-refresh {
			position: absolute;
			right: 20px;
			top: 33px;
			color: #fff
		}
		
		.user-refresh i {
			font-size: 20px;
		}
		
		.user-vip{
			position: absolute;
			bottom: 0;
			right: 120px;
			width: 70px;
		}
		
		.user-bond{
			position: absolute;
			left: 0px;
			right: 0px;
			bottom: 0px;
			z-index: 100;
			padding: 10px 0 5px 0;
			background-color: #3d9953;
		}
		.user-bond > div{
			text-align: center;
		}
		.user-bond p{
			font-size: 12px;
			color:#9ae5ab
		}
		.user-bond .price{
			color: #fff;
			font-size: 20px;
		}
		
		.weui-cell__hd i {
			font-size: 22px;
			margin-right: 5px;
			color: #888;
		}
		
		.weui-cell__bd p {
			font-size: 15px;
		}
		
		.weui-cell__ft {
			font-size: 14px;
		}
	</style>

	<body>

		<div id="app"> 
			<div class="user-info bg-line"> 
				<img :src="userinfo.icon_img+'@!200x200'" class="user-icon img_cover" v-if="userinfo.icon" onclick="clicked('my_setting.html','pop-in');">  
				<img src="images/no-touxiang.png" class="user-icon" v-else onclick="clicked('my_setting.html','pop-in');">
				<div class="user-name" v-if="userinfo.real_name">{{userinfo.real_name}} <i class="iconfont icon-renzhengyuangong"></i></div>
				<div class="user-name" v-else>未设置昵称</div>
				<div class="user-level" >聚石合伙人 编号:{{userinfo.agent_sn}}</div>
				<div class="user-edit" onclick="clicked('my_setting.html','pop-in');"><i class="iconfont icon-post"></i> 编辑</div>
				<div class="user-refresh" @click="refresh()"><i class="iconfont icon-refresh"></i></div>
				<div class="user-bond bg-line" flex="dir:left box:mean">
					<div style="border-right: #2b8740 1px solid;">
						<p>保证金</p>
						<p class="price">{{userinfo.bond}}元</p>
					</div>
					<div style="border-left: #4eaf64 1px solid;">
						<p>已使用</p>
						<p class="price">{{userinfo.arrears}}元</p>
					</div> 
				</div>
			</div>
			<div class="main-body">
				
				<div class="weui-cells" style="margin-top: 10px;">
					<a class="weui-cell weui-cell_access" href="javascript:clicked('my_zhangben.html','pop-in');">
						<div class="weui-cell__hd"><i class="iconfont icon-gonglve"></i></div>
						<div class="weui-cell__bd">
							<p>我的账本</p>
						</div>
						<div class="weui-cell__ft">查看</div>
					</a>
				</div>
				
				<div class="weui-cells" style="margin-top: 10px;">
					
					<a class="weui-cell weui-cell_access" href="javascript:;" @click="viewShop">
						<div class="weui-cell__hd"><i class="iconfont icon-shop"></i></div>
						<div class="weui-cell__bd">
							<p>我的聚小店</p>
						</div>
						<div class="weui-cell__ft">微信版</div>
					</a>
					
					<a class="weui-cell weui-cell_access" href="javascript:clicked('my_shop.html','pop-in');">
						<div class="weui-cell__hd"><i class="iconfont icon-write"></i></div>
						<div class="weui-cell__bd">
							<p>小店设置</p>
						</div>
						<div class="weui-cell__ft">设置</div>
					</a>
					
					<a class="weui-cell weui-cell_access" href="javascript:clicked('my_shop_agent.html','pop-in');">
						<div class="weui-cell__hd"><i class="iconfont icon-group"></i></div>
						<div class="weui-cell__bd">
							<p>我的合伙人</p>
						</div>
						<div class="weui-cell__ft">查看</div>
					</a>
					
					
					<a class="weui-cell weui-cell_access" href="javascript:clicked('favor.html','pop-in');">
						<div class="weui-cell__hd"><i class="iconfont icon-favor"></i></div>
						<div class="weui-cell__bd">
							<p>我的收藏</p>
						</div>
						<div class="weui-cell__ft">查看</div>
					</a>
					
				</div>

				<div class="weui-cells" style="margin-top: 10px;">
					<a class="weui-cell weui-cell_access" href="javascript:;" @click="about">
						<div class="weui-cell__hd"><i class="iconfont icon-warn"></i></div>
						<div class="weui-cell__bd">
							<p>关于我们</p>
						</div>
						<div class="weui-cell__ft"></div>
					</a>
					
					<a class="weui-cell weui-cell_access" href="javascript:;" @click="tel">
						<div class="weui-cell__hd"><i class="iconfont icon-phone"></i></div>
						<div class="weui-cell__bd">
							<p>联系我们</p>
						</div>
						<div class="weui-cell__ft">4000-111-807</div>
					</a>
					
					<a class="weui-cell weui-cell_access" href="javascript:clicked('feedback.html','pop-in');">
						<div class="weui-cell__hd"><i class="iconfont icon-comment"></i></div>
						<div class="weui-cell__bd">
							<p>意见反馈</p>
						</div>
						<div class="weui-cell__ft">反馈</div>
					</a>
					
				</div>

				<div class="weui-cells" style="margin-top: 10px;">
					<a class="weui-cell weui-cell_access" href="javascript:;" @click="clearCache">
						<div class="weui-cell__hd"><i class="iconfont icon-delete"></i></div>
						<div class="weui-cell__bd">
							<p>清除缓存</p>
						</div>
						<div class="weui-cell__ft">{{cacheSize}}</div>
					</a>
				</div>

				<div class="weui-cells__title">当前版本：{{version}}</div>
				<div class="weui-btn-area">
					<a href="javascript:;" class="weui-btn weui-btn_default" onclick="logout()">退出登录</a>
				</div>
				<div style="height:30px"></div>
			</div>

		</div>

		<script src="js/mui.min.js"></script>
		<script src="js/jquery-2.1.4.js"></script>
		<script src="js/jquery-weui.min.js"></script>
		<script src="js/vue.js"></script>
		<script src="js/smarge.js"></script>
		<script src="js/common.js"></script>
		<script type="text/javascript" charset="utf-8">
			mui.init();

			function clearCache() {
				plus.io.resolveLocalFileSystemURL('_downloads/image', function(entry) {
					var directoryReader = entry.createReader();
					directoryReader.readEntries(function(entries) {
						//log(entries)
						if(entries.length > 0) {
							//plus.nativeUI.showWaiting('正在清除')
						} else {
							mui.toast('很干净，暂时没有缓存');
						}
						var i, files = 0;
						for(i = 0; i < entries.length; i++) {
							if(entries[i].name) {
								plus.io.resolveLocalFileSystemURL('_downloads/image/' + entries[i].name, function(entry) {
									entry.remove(function(entry) {
										files++
										log("文件删除成功==");
										if(files === entries.length) {
											mui.toast('已清除'+files+"张缓存图片 \n dddddd");
											plus.nativeUI.closeWaiting()
										}
									}, function(e) {
										console.log("文件删除失败=");
									}); 
								});
							}
						}
					}, function(e) {
						alert("Read entries failed: " + e.message);
					});

				}, function(e) {
					alert("Request file system failed: " + e.message);
				});
			}
			
			
			
			
			mui.plusReady(function() {

				window.updateData = function() {
					vm.refresh();
				}
				
				
				
				
				var vm = new Vue({
					el: "#app",
					data: {
						userinfo: '',
						version: '',
						cacheSize:"", 
					},
					mounted: function() {
						this.inits();
						this.cache();
					},
					methods: {
						inits: function() {
							var vm = this;
							Get(SERVER_URL+'&c=User&a=getInfo', {}, function(data) {
				            	if(data.status){
				            		Smarge.set('userinfo', data.info);
				            		vm.userinfo = data.info;
				            	}
				            })
							
							plus.runtime.getProperty(plus.runtime.appid, function(inf) {
								vm.version = inf.version;
							});
							
						},
						refresh: function() {
							var vm = this;
							plus.nativeUI.showWaiting()
							Get(SERVER_URL+'&c=User&a=getInfo', {}, function(data) {
				            	if(data.status){
				            		Smarge.set('userinfo', data.info);
				            		vm.userinfo = data.info;
				            		log(vm.userinfo)
				            		plus.nativeUI.closeWaiting();
				            	}
				            })
						},
						cache : function(){
							
							var vm = this;
							plus.io.resolveLocalFileSystemURL('_downloads/image', function(entry) {
								var directoryReader = entry.createReader();
								directoryReader.readEntries(function(entries) {
									var i, size = 0,files = 0;
									for(i = 0; i < entries.length; i++) {
										if(entries[i].name) {
											plus.io.resolveLocalFileSystemURL('_downloads/image/' + entries[i].name, function(entry) {
												entry.getMetadata( function ( metadata ) {
														files++
														size += metadata.size; 
														if(files === entries.length) {
															vm.cacheSize = ((size/(1024*1024)).toFixed(2)+"MB") 
														}
													});
											});
										}
									}
									
								});
			
							});
							
						},
						clearCache : function(){
							var vm = this;
							plus.io.resolveLocalFileSystemURL('_downloads/image', function(entry) {
								var directoryReader = entry.createReader();
								directoryReader.readEntries(function(entries) {
									//log(entries)
									if(entries.length > 0) {
										//plus.nativeUI.showWaiting('正在清除')
									} else {
										mui.toast('很干净，暂时没有缓存');
									}
									var i, files = 0;
									for(i = 0; i < entries.length; i++) {
										if(entries[i].name) {
											plus.io.resolveLocalFileSystemURL('_downloads/image/' + entries[i].name, function(entry) {
												entry.remove(function(entry) {
													files++
													log("文件删除成功==");
													if(files === entries.length) {
														mui.toast('已清除'+files+"张缓存图片 \n "+vm.cacheSize); 
														vm.cacheSize = "0MB"
														plus.nativeUI.closeWaiting()
													}
												}, function(e) {
													console.log("文件删除失败=");
												}); 
											});
										}
									}
								}, function(e) {
									alert("Read entries failed: " + e.message);
								});
			
							}, function(e) {
								alert("Request file system failed: " + e.message);
							});
						},
						tel : function() {
							window.location.href = "tel:4000111807";
						},
						about : function(){
							var btnArray = [{
								title: "聚石云库"
							}, {
								title: "聚石合伙人"
							}, {
								title: "聚石学院"
							}, {
								title: "聚石通宝"
							}];
							plus.nativeUI.actionSheet({
								title: "关于聚石",
								cancel: "取消",
								buttons: btnArray
							}, function(e) {
								var index = e.index;
								switch(index) {
									case 0:
										break;
									case 1:
										clicked('about.html', 'pop-in');
										break;
									case 2:
										clicked('about_jiameng.html', 'pop-in'); 
										break;
									case 3:
										clicked('about_school.html', 'pop-in');
										break;
									case 4:
										clicked('about_tongbao.html', 'pop-in');
										break;
									default:
										// 其它
										break;
								}
							});
						},
						viewShop : function(){
							var vm = this; 
							var btnArray = [ {
								title: "店铺二维码"
							}, {
								title: "复制店铺链接"
							}];
							plus.nativeUI.actionSheet({
								title: "我的聚小店",
								cancel: "取消",
								buttons: btnArray
							}, function(e) {
								var index = e.index;
								switch(index) {
									case 0:
										break;
									case 1:
										clicked('my_shop_qr.html', 'pop-in'); 
										break;
									case 2:
										copyToClip('http://shop.51jushi.com/Shop/index/id/'+vm.userinfo.id);  
										break;
									default:
										// 其它
										break;
								}
							});
						}
					}
				})

			});
		</script>
	</body>

</html>